﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Agility.TestProject.AppDriver;
using Agility.Wcf.ClientProxy;
using OneOfAKind.Toolbox.NetFxTools;

namespace Agility.Testing.WcfProxy
{
    [TestFixture]
    public class CookieManagerTests
    {
        private string userName;
        AppDriverBase appDriverBase;

        #region optional Setup and Teardown methods

        [TestFixtureSetUp]
        public void SetupFixture()
        {
            appDriverBase = new AppDriverBase();
        }

        //[TestFixtureTearDown]
        //public void TeardownFixture()
        //{
        //}

        [SetUp]
        public void SetupTest()
        {
            userName = appDriverBase.CreateUser();
        }

        [TearDown]
        public void TeardownTest()
        {
            appDriverBase.Cleanup();
        }

        #endregion

        #region UnitTests

        [Test]
        [Category("UnitTest")]
        public void TestGetInstance()
        {
            // Arrange
            CookieManagerMessageInspector target = CookieManagerMessageInspector.GetInstance();

            // Act
            CookieManagerMessageInspector target2 = CookieManagerMessageInspector.GetInstance();

            // Assert
            Assert.That(target, Is.Not.Null);
            Assert.That(target, Is.TypeOf(typeof(CookieManagerMessageInspector)));
            Assert.That(target, Is.SameAs(target2));
        }

        #endregion

        #region ComponentTests

        [Test]
        [Category("ComponentTest")]
        public void TestGetAuthenticationCookie()
        {
            // Arrange
            AgilityClientProxy agilityProxy = AgilityClientProxy.GetInstance(new Uri("http://localhost:52878/"));
            bool result;
            CookieManagerMessageInspector target = null;
            agilityProxy.KeepMeLoggedOn = true;

            // Act
            agilityProxy.LogOn(userName, "Test##100");
            result = agilityProxy.IsLoggedOn;
            target = CookieManagerMessageInspector.GetInstance();
            
            // Assert
            Assert.That(result, Is.True);
            Assert.That(target.AuthenticationCookie, Is.Not.Null);
        }

        #endregion

    }
}
